/*     */ package com.zimbra.cs.index;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.stats.Counter;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.stats.ZimbraPerf;
/*     */ import java.io.File;
/*     */ import java.io.IOException;
/*     */ import java.util.Collection;
/*     */ import org.apache.lucene.store.Directory;
/*     */ import org.apache.lucene.store.FSDirectory;
/*     */ import org.apache.lucene.store.IndexInput;
/*     */ import org.apache.lucene.store.IndexOutput;
/*     */ import org.apache.lucene.store.Lock;
/*     */ import org.apache.lucene.store.LockFactory;
/*     */ import org.apache.lucene.store.MMapDirectory;
/*     */ import org.apache.lucene.store.NIOFSDirectory;
/*     */ import org.apache.lucene.store.SimpleFSDirectory;
/*     */ import org.apache.lucene.store.SingleInstanceLockFactory;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class LuceneDirectory
/*     */   extends Directory
/*     */ {
/*     */   private final FSDirectory directory;
/*     */   
/*     */   private LuceneDirectory(FSDirectory dir)
/*     */   {
/*  50 */     this.directory = dir;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static LuceneDirectory open(File path)
/*     */     throws IOException
/*     */   {
/*  85 */     String impl = LC.zimbra_index_lucene_io_impl.value();
/*     */     FSDirectory dir;
/*  87 */     FSDirectory dir; if ("nio".equals(impl)) {
/*  88 */       dir = new NIOFSDirectory(path, new SingleInstanceLockFactory()); } else { FSDirectory dir;
/*  89 */       if ("mmap".equals(impl)) {
/*  90 */         dir = new MMapDirectory(path, new SingleInstanceLockFactory()); } else { FSDirectory dir;
/*  91 */         if ("simple".equals(impl)) {
/*  92 */           dir = new SimpleFSDirectory(path, new SingleInstanceLockFactory());
/*     */         } else
/*  94 */           dir = FSDirectory.open(path, new SingleInstanceLockFactory());
/*     */       } }
/*  96 */     ZimbraLog.index.info("OpenLuceneIndex impl=%s,dir=%s", new Object[] { dir.getClass().getSimpleName(), path });
/*  97 */     return new LuceneDirectory(dir);
/*     */   }
/*     */   
/*     */   public File getDirectory() {
/* 101 */     return this.directory.getDirectory();
/*     */   }
/*     */   
/*     */   public String[] listAll() throws IOException
/*     */   {
/* 106 */     return this.directory.listAll();
/*     */   }
/*     */   
/*     */   public boolean fileExists(String name) throws IOException
/*     */   {
/* 111 */     return this.directory.fileExists(name);
/*     */   }
/*     */   
/*     */   public long fileModified(String name) throws IOException
/*     */   {
/* 116 */     return this.directory.fileModified(name);
/*     */   }
/*     */   
/*     */   @Deprecated
/*     */   public void touchFile(String name) throws IOException
/*     */   {
/* 122 */     this.directory.touchFile(name);
/*     */   }
/*     */   
/*     */   public void deleteFile(String name) throws IOException
/*     */   {
/* 127 */     this.directory.deleteFile(name);
/*     */   }
/*     */   
/*     */   public long fileLength(String name) throws IOException
/*     */   {
/* 132 */     return this.directory.fileLength(name);
/*     */   }
/*     */   
/*     */   public IndexOutput createOutput(String name)
/*     */     throws IOException
/*     */   {
/* 138 */     return new LuceneIndexOutput(this.directory.createOutput(name));
/*     */   }
/*     */   
/*     */   public void sync(Collection<String> names) throws IOException
/*     */   {
/* 143 */     this.directory.sync(names);
/*     */   }
/*     */   
/*     */   public IndexInput openInput(String name) throws IOException
/*     */   {
/* 148 */     return new LuceneIndexInput(this.directory.openInput(name));
/*     */   }
/*     */   
/*     */   public IndexInput openInput(String name, int bufferSize) throws IOException
/*     */   {
/* 153 */     return new LuceneIndexInput(this.directory.openInput(name, bufferSize));
/*     */   }
/*     */   
/*     */   public Lock makeLock(String name)
/*     */   {
/* 158 */     return this.directory.makeLock(name);
/*     */   }
/*     */   
/*     */   public void clearLock(String name) throws IOException
/*     */   {
/* 163 */     this.directory.clearLock(name);
/*     */   }
/*     */   
/*     */   public void close() throws IOException
/*     */   {
/* 168 */     this.directory.close();
/*     */   }
/*     */   
/*     */   public void setLockFactory(LockFactory lockFactory) throws IOException
/*     */   {
/* 173 */     this.directory.setLockFactory(lockFactory);
/*     */   }
/*     */   
/*     */   public LockFactory getLockFactory()
/*     */   {
/* 178 */     return this.directory.getLockFactory();
/*     */   }
/*     */   
/*     */   public String getLockID()
/*     */   {
/* 183 */     return this.directory.getLockID();
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/* 188 */     return this.directory.toString();
/*     */   }
/*     */   
/*     */   private static final class LuceneIndexInput extends IndexInput {
/*     */     private final IndexInput input;
/* 193 */     private boolean disableCounters = LC.zimbra_index_disable_perf_counters.booleanValue();
/*     */     
/*     */     LuceneIndexInput(IndexInput in) {
/* 196 */       this.input = in;
/*     */     }
/*     */     
/*     */     public byte readByte() throws IOException
/*     */     {
/* 201 */       if (!this.disableCounters) {
/* 202 */         ZimbraPerf.COUNTER_IDX_BYTES_READ.increment(1L);
/*     */       }
/* 204 */       return this.input.readByte();
/*     */     }
/*     */     
/*     */     public void readBytes(byte[] b, int offset, int len) throws IOException
/*     */     {
/* 209 */       if (!this.disableCounters) {
/* 210 */         ZimbraPerf.COUNTER_IDX_BYTES_READ.increment(len);
/*     */       }
/* 212 */       this.input.readBytes(b, offset, len);
/*     */     }
/*     */     
/*     */     public void readBytes(byte[] b, int offset, int len, boolean useBuffer)
/*     */       throws IOException
/*     */     {
/* 218 */       if (!this.disableCounters) {
/* 219 */         ZimbraPerf.COUNTER_IDX_BYTES_READ.increment(len);
/*     */       }
/* 221 */       this.input.readBytes(b, offset, len, useBuffer);
/*     */     }
/*     */     
/*     */     public void setModifiedUTF8StringsMode()
/*     */     {
/* 226 */       this.input.setModifiedUTF8StringsMode();
/*     */     }
/*     */     
/*     */     public void close() throws IOException
/*     */     {
/* 231 */       this.input.close();
/*     */     }
/*     */     
/*     */     public long getFilePointer()
/*     */     {
/* 236 */       return this.input.getFilePointer();
/*     */     }
/*     */     
/*     */     public void seek(long pos) throws IOException
/*     */     {
/* 241 */       this.input.seek(pos);
/*     */     }
/*     */     
/*     */     public long length()
/*     */     {
/* 246 */       return this.input.length();
/*     */     }
/*     */     
/*     */     public Object clone()
/*     */     {
/* 251 */       return new LuceneIndexInput((IndexInput)this.input.clone());
/*     */     }
/*     */   }
/*     */   
/*     */   private static final class LuceneIndexOutput extends IndexOutput {
/*     */     private final IndexOutput output;
/* 257 */     private boolean disableCounters = LC.zimbra_index_disable_perf_counters.booleanValue();
/*     */     
/*     */     LuceneIndexOutput(IndexOutput out) {
/* 260 */       this.output = out;
/*     */     }
/*     */     
/*     */     public void writeByte(byte b) throws IOException
/*     */     {
/* 265 */       if (!this.disableCounters) {
/* 266 */         ZimbraPerf.COUNTER_IDX_BYTES_WRITTEN.increment(1L);
/*     */       }
/* 268 */       this.output.writeByte(b);
/*     */     }
/*     */     
/*     */     public void writeBytes(byte[] b, int len) throws IOException
/*     */     {
/* 273 */       if (!this.disableCounters) {
/* 274 */         ZimbraPerf.COUNTER_IDX_BYTES_WRITTEN.increment(len);
/*     */       }
/* 276 */       this.output.writeBytes(b, len);
/*     */     }
/*     */     
/*     */     public void writeBytes(byte[] b, int offset, int len) throws IOException
/*     */     {
/* 281 */       if (!this.disableCounters) {
/* 282 */         ZimbraPerf.COUNTER_IDX_BYTES_WRITTEN.increment(len);
/*     */       }
/* 284 */       this.output.writeBytes(b, offset, len);
/*     */     }
/*     */     
/*     */     public void flush() throws IOException
/*     */     {
/* 289 */       this.output.flush();
/*     */     }
/*     */     
/*     */     public void close() throws IOException
/*     */     {
/* 294 */       this.output.close();
/*     */     }
/*     */     
/*     */     public long getFilePointer()
/*     */     {
/* 299 */       return this.output.getFilePointer();
/*     */     }
/*     */     
/*     */     public void seek(long pos) throws IOException
/*     */     {
/* 304 */       this.output.seek(pos);
/*     */     }
/*     */     
/*     */     public long length() throws IOException
/*     */     {
/* 309 */       return this.output.length();
/*     */     }
/*     */     
/*     */     public void setLength(long len) throws IOException
/*     */     {
/* 314 */       this.output.setLength(len);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/index/LuceneDirectory.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */